The simple scripts in life are often the best
Possibly my longest blog post title ever?
Anyway, here’s a link to today’s little bit of scripting. I’ve now written this script three or four times, so I figure that means it’s useful and maybe worth keeping around. I’m calling it dir2tree and all it does is take a (sorted) list of pathnames and convert it into a tree structure. So, eg:
$ dpkg -L samba | grep man.*gz /usr/share/man/man8/mksmbpasswd.8.gz /usr/share/man/man8/eventlogadm.8.gz /usr/share/man/man8/tdbbackup.8.gz /usr/share/man/man8/pdbedit.8.gz /usr/share/man/man8/smbd.8.gz /usr/share/man/man8/nmbd.8.gz /usr/share/man/man1/smbstatus.1.gz /usr/share/man/man1/profiles.1.gz /usr/share/man/man1/smbcontrol.1.gz
becomes
$ dpkg -L samba | grep man.*gz | sort | dir2tree / usr/ share/ man/ man1/ profiles.1.gz smbcontrol.1.gz smbstatus.1.gz man8/ eventlogadm.8.gz mksmbpasswd.8.gz nmbd.8.gz pdbedit.8.gz smbd.8.gz tdbbackup.8.gz
So yeah. There you go.
(A related useful tool is tree, which generates a prettier tree and does the directory walking itself. I wanted something that I could use with find, and I couldn’t spot anything that already existed.)